﻿namespace Example.Cryptography
{
    using System;
    using System.Diagnostics.CodeAnalysis;

    [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Ciphertext", Justification = "The casing is correct.")]
    [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Sha", Justification = "The casing is correct.")]
    public sealed class ShaCiphertext
    {
        private byte[] _ciphertext;

        private Salt _salt;

        [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "ciphertext", Justification = "The casing is correct.")]
        public ShaCiphertext(Salt salt, 
                             byte[] ciphertext)
        {
            Salt = salt;
            Ciphertext = ciphertext;
        }

        public Salt Salt
        {
            get
            {
                return _salt;
            }

            private set
            {
                if (null == value)
                {
                    throw new ArgumentNullException("value");
                }

                _salt = value;
            }
        }

        private byte[] Ciphertext
        {
            get
            {
                return _ciphertext;
            }

            set
            {
                if (null == value)
                {
                    throw new ArgumentNullException("value");
                }

                _ciphertext = value;
            }
        }

        public byte[] ToBytes()
        {
            return Ciphertext;
        }

        public override string ToString()
        {
            return Convert.ToBase64String(Ciphertext);
        }
    }
}